<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *知识
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'执行资料'),
);
$return['project_status']=$this->project_status;
$return['check_status']=$this->check_status;
$this->model('model')->check_gs($user);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'user_id'=>$this->user_id);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['cname'])){
		$params['cname like']='%'.trim($_RQ['cname']).'%';
		$return['params']['cname']=$_RQ['cname'];
	}
	if(!empty($_RQ['sn'])){
		$params['sn like']='%'.trim($_RQ['sn']).'%';
		$return['params']['sn']=$_RQ['sn'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}else{
		if($_SESSION['os']!='windows'){
			$return['params']['status']=0;
			$params['status']=0;
		}
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_baobiao_project',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$user=pdo_get('jy_baobiao_project_cuser',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['user_id']));
			$member=pdo_get('core_members',array('id'=>$item['mid']),array('credit1','credit2','mobile','avatar','nickname','username','sex'));
			$item['member']=$member;
			$item['user']=$user;
			$item['statustitle']=$this->project_status[$item['status']];
			$item['pidtitle']=pdo_getcolumn('jy_baobiao_project_group',array('id'=>$item['pid']),'title');
			$item['cidtitle']=pdo_getcolumn('jy_baobiao_project_group',array('id'=>$item['cid']),'title');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'这里只显示待专家审核的项目，和刚审核的项目！','edit'=>false,'list'=>array(
			//array('name'=>'sn','title'=>'项目编码','type'=>'string'),
			array('name'=>'title','title'=>'项目名称','type'=>'string'),
			array('name'=>'user.cname','title'=>'申报单位','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'project_status'),
			//array('name'=>'fa_starttime','title'=>'发售起始时间','type'=>'time'),
			//array('name'=>'fa_edntime','title'=>'发售结束时间','type'=>'time'),
			array('name'=>'createtime','title'=>'申请时间','type'=>'time'),
		),'action' =>array(
			 array('type'=>'href','op'=>'edit','title'=>'查看上传'),
		)),
		'search'=>array(
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'project_status'),
			array('name'=>'sn','width'=>15,'title'=>'项目编码','type'=>'string'),
			array('name'=>'cname','width'=>15,'title'=>'申报单位','type'=>'string'),
		)
	);
	if($_SESSION['os']=='windows'){
		$return['htmls']=$htmls;
	}
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_baobiao_project',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));		
	}else{
		$item=array('type'=>$this->session('type'),'star'=>3);
	}
	$cuser=pdo_get('jy_baobiao_project_cuser',array('id'=>$this->user_id,'uniacid'=>$_SESSION['uniacid']));
	$item['file']=json_decode($item['file'],true);
	$item['image']=$item['file']['image'];
	$item['wendang']=$item['file']['wendang'];
	$item['video']=$item['file']['video'];
	$item['zip']=$item['file']['zip'];
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回列表'),
		),
		'edit'=>array(
			array('name'=>'title','title'=>'申报项目名称','type'=>'copy'),
			array('type'=>'array','name'=>'image','title'=>'执行资料(图片)上传','add_tip'=>'添加一个图片',
								'list'=>array(
									array('type'=>'string','name'=>'title','title'=>'图片名称'),	
									array('type'=>'image','name'=>'url','title'=>'图片'),
								),
								'details'=>array(
									array('type'=>'string','name'=>'title','title'=>'图片名称'),	
									array('type'=>'image','name'=>'url','title'=>'上传图片'),
								)
			),
			array('type'=>'array','name'=>'wendang','title'=>'执行资料(文档)上传','add_tip'=>'添加一个文档',
								'list'=>array(
									array('type'=>'string','name'=>'title','title'=>'文档名称'),	
									array('type'=>'string','name'=>'url','title'=>'文档路径'),
								),
								'details'=>array(
									array('type'=>'string','name'=>'title','title'=>'文档名称'),	
									array('type'=>'upfile','name'=>'url','title'=>'上传文档'),
								)
			),
			array('type'=>'array','name'=>'video','title'=>'执行资料(视频)上传','add_tip'=>'添加一个视频',
								'list'=>array(
									array('type'=>'string','name'=>'title','title'=>'视频名称'),	
									array('type'=>'string','name'=>'url','title'=>'视频路径'),
								),
								'details'=>array(
									array('type'=>'string','name'=>'title','title'=>'视频名称'),	
									array('type'=>'video','name'=>'url','title'=>'上传视频'),
								)
			),
			array('type'=>'array','name'=>'zip','title'=>'执行资料(压缩包)上传','add_tip'=>'添加一个压缩包',
								'list'=>array(
									array('type'=>'string','name'=>'title','title'=>'压缩包名称'),	
									array('type'=>'string','name'=>'url','title'=>'压缩包路径'),
								),
								'details'=>array(
									array('type'=>'string','name'=>'title','title'=>'压缩包名称'),	
									array('type'=>'upfile','name'=>'url','title'=>'上传压缩包'),
								)
			),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if($postdata['status'] && $postdata['status']!=10){
		exi('项目已进入审核流程，不能编辑！','error');
	}
	$postdata['file']=array(
		'image'=>$postdata['image'],
		'wendang'=>$postdata['wendang'],
		'video'=>$postdata['video'],
		'zip'=>$postdata['zip'],
	);
	$data=array(
		'file'=>ijson_encode($postdata['file']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_baobiao_project',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		exi('请选择项目！','error');
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	exi('不能删除项目！','error');
}